import * as Koa from 'koa';
import { getConfigValues } from '../entity/applet-config';

const errorMsg = `服务器错误：${'applet_config'}`;
const successMsg = `成功：${'applet_config'}`;

export default class ConfigService {
  getConfigValues = async (ctx: Koa.Context) => {
    try {
      // 相等的条件
      const result: any = await getConfigValues(ctx);
      if (!result) {
        ctx.fail(null, result.msg || errorMsg, -1);
      } else if (!result.success) {
        ctx.fail(null, result.msg || errorMsg, -1);
      } else {
        ctx.success(result.data || [], successMsg);
      }
    } catch (error) {
      ctx.fail(null, errorMsg, -1);
    }
  };
}
